<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Croptype;

/* @var $this yii\web\View */
/* @var $searchModel app\models\searchs\CroptypeeSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

//以下代码为生成多级结构breadcrumbers
$parent = Croptype::findone($id);
$level=$parent->level;
for($i=0;$i<$level;$i+=1)
{
    $l=$level;
    $parent = Croptype::findone($id);
    while($l!=$i){
        $parent = Croptype::findone($parent->pid);
        $l=$parent->level;
    }
    $this->params['breadcrumbs'][] = ['label'=>$parent->name . "类",'url'=>['index','id'=>$parent->id]];
}
$parent = Croptype::findone($id);
$this->title=$parent->name."类";
$this->params['breadcrumbs'][] = ['label'=>$parent->name . "类",'url'=>['index','id'=>$parent->id]];
//=============================
?>
<div class="croptype-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>

        <?= Html::a('新增'.$this->title, ['create','id'=>$parent->id,], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            'name',
            //'pid'
            'code',
            //'level',
            'comment',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
